const https = require("https");
// 引入cheerio,相当于后端的jquery
const cheerio = require("cheerio");

https.get("https://www.microsoftstore.com.cn/", (res) => {
  let result;
  res.on("data", (chunk) => {
    result += chunk;
  });
  res.on("end", () => {
    // console.log(result);
    const $ = cheerio.load(result);
    let arr = [];
    $(".recommends-swiper-container")
      .eq(0)
      .find(".swiper-slide")
      .each((index, item) => {
        // console.log($(item).find(".inner").html());
        // console.log($(item).find("strong span").eq(0).html());
        arr.push({
          name: $(item).find(".inner").html(),
          price: $(item).find("strong span").eq(0).html(),
          img: $(item).find("img").attr("src"),
        });
      });
    console.log(arr);
  });
});
